package com.ruoyi.project.monitor.job.task;

import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.presentation.domain.DataPresentation;
import com.ruoyi.project.system.presentation.service.IDataPresentationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.ruoyi.common.utils.StringUtils;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * 定时任务调度测试
 * 
 * @author ruoyi
 */
@Component("ryTask")
public class RyTask
{
    @Autowired
    private IDataPresentationService dataPresentationService;

    public void ryMultipleParams(String s, Boolean b, Long l, Double d, Integer i)
    {
        System.out.println(StringUtils.format("执行多参方法： 字符串类型{}，布尔类型{}，长整型{}，浮点型{}，整形{}", s, b, l, d, i));
    }

    public void ryParams(String params)
    {
        System.out.println("执行有参方法：" + params);
    }

    public void ryNoParams()
    {
        System.out.println("执行无参方法");
    }
    @Log(title = "数据展示", businessType = BusinessType.INSERT)
    public void addSave()
    {
        //Calendar calendar = Calendar.getInstance();
        //获取当时间前一天
        Calendar calendar1 = Calendar.getInstance();
        calendar1.add(Calendar.DATE, -1);

        //获取前一天是本月的第几天
        Long day = (long)calendar1.get(Calendar.DAY_OF_MONTH);
        //获取前一天是本年的第几周
        Long week = (long)calendar1.get(Calendar.WEEK_OF_YEAR);
        //获取前一天是本年的第几个月
        Long month = (long)calendar1.get(Calendar.MONTH)+1;
        //获取前一天是本年的第几季度
        long quarter ;
        if (month >= 1 && month <= 3) {
            quarter = 1;
        } else if (month >= 4 && month <= 6) {
            quarter = 2;
        } else if (month >= 7 && month <= 9) {
            quarter = 3;
        } else {
            quarter = 4;
        }
        //获取前一天是第哪一年
        Long year = (long)calendar1.get(Calendar.YEAR);
        //获取本周第几天
        Integer dayOfWeek = calendar1.get(Calendar.DAY_OF_WEEK);
        //获取当前日期
//        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS");
//        Date date=new Date();
//        String formatDate = df.format(date);

        //将当前时间转为时间戳
        long  endTime= Calendar.getInstance().getTimeInMillis()/1000;
        //将前一天时间转为时间戳
        Date time = calendar1.getTime();
        long beginTime = time.getTime()/1000;


        List<DataPresentation> dataPresentations = dataPresentationService.selectDataPresentationByTimeHorizon(beginTime,endTime);
        for (int i = 0; i < dataPresentations.size(); i++) {
            DataPresentation dataPresentation = new DataPresentation();

            DataPresentation dataPresentation1 = dataPresentations.get(i);
            Long applicationNumber = dataPresentation1.getApplicationNumber();
            Long equipmentId = dataPresentation1.getEquipmentId();
            Long throughNumber = dataPresentation1.getThroughNumber();
            String userName = dataPresentation1.getUserName();
            String verbalTrick = dataPresentation1.getVerbalTrick();
            String wechatId = dataPresentation1.getWechatId();

            dataPresentation.setApplicationNumber(applicationNumber);
            dataPresentation.setEquipmentId(equipmentId);
            dataPresentation.setThroughNumber(throughNumber);
            dataPresentation.setUserName(userName);
            dataPresentation.setVerbalTrick(verbalTrick);
            dataPresentation.setWechatId(wechatId);
            dataPresentation.setDay(day);
            dataPresentation.setWeek(week);
            dataPresentation.setMonth(month);
            dataPresentation.setYear(year);
            dataPresentation.setSeason(quarter);
            dataPresentation.setDayOfWeek(dayOfWeek);
            dataPresentationService.insertDataPresentation(dataPresentation);
        }
        System.out.println("执行无参方法");
    }

}
